'''
    获取网页中的图片
'''
# 请求网页 获取
import requests
import re
import time
# headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'}
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0'}

url1 = 'https://www.meizitu.com/a/'

num = 5203
i = 132
while num < 6000 :
    
    num += 1
    urls = url1 + str(num) + ".html"
    print(urls)
        
    response = requests.get(urls, headers = headers)
    htmls = response.text

    # 解析网页
    url = re.findall('<img alt=".*?" src="(.*?)" />', htmls)
    # print(url)

    # 保存图片
    for picture in url:
        i = i + 1    
        time.sleep(10)

        # 获取图片链接已反斜杠为分割最后一个分割点的字符串
        file_name = str(i) + '.jpg'
        # 
        response = requests.get(picture, headers = headers)
        with open(file_name, 'wb') as f:
            f.write(response.content)
            f.close()
   